package com.ruoyi.controller;

import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.domain.TCwDealPerDay;
import com.ruoyi.domainVo.TCwDealPerDayVo;
import com.ruoyi.service.ITCwDealPerDayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

import static com.ruoyi.common.core.web.domain.AjaxResult.success;

@RestController
@RequestMapping("/calculate")
public class CalculateController {
    @Autowired
    private ITCwDealPerDayService tCwDealPerDayService;
    /**
     * 计算
     * @param
     * @return
     */
    @RequiresPermissions("property:property:cal")
    @GetMapping("/cal/{query}")
    public AjaxResult cal(@PathVariable("query") Long id){
        System.out.println(id);

        BigDecimal sum = new BigDecimal("0"),yajin = new BigDecimal("0"),
                zujin = new BigDecimal("0"), dianfei = new BigDecimal("0"),shuifei = new BigDecimal("0"),
                kuandai = new BigDecimal("0"),ranqifei = new BigDecimal("0"),
                youxiandianshui = new BigDecimal("0"),qite = new BigDecimal("0");
        TCwDealPerDayVo tCwDealPerDay = new TCwDealPerDayVo();
        tCwDealPerDay.setOperationType(id);
        List<TCwDealPerDay> list = tCwDealPerDayService.selectTCwDealPerDayList(tCwDealPerDay);
        for (TCwDealPerDay cwDealPerDay : list) {
            sum= sum.add(cwDealPerDay.getTotal()) ;
            yajin=yajin.add(cwDealPerDay.getDeposit());
            zujin= zujin.add(cwDealPerDay.getRent());
            dianfei= dianfei.add(cwDealPerDay.getElectricityFee());
            shuifei=shuifei.add(cwDealPerDay.getWaterFee());
            kuandai=kuandai.add(cwDealPerDay.getNetFee());
            ranqifei=ranqifei.add(cwDealPerDay.getGasFee());
            youxiandianshui=youxiandianshui.add(cwDealPerDay.getCableFee());
            qite=qite.add(cwDealPerDay.getOtherFee());
        }
        TCwDealPerDayVo tCwDealPerDayVo = new TCwDealPerDayVo(yajin,zujin,dianfei,shuifei,kuandai,ranqifei,youxiandianshui,qite,sum);
        return success(tCwDealPerDayVo);
    }
}
